/**
 * Created by liguangsong on 16/8/12.
 */
import React from 'react'
import '../../css/container/index.css'
import Content from './content.js'
import SiderBar from './sideBar.js'
import Page from './page.js'
import { selectPage } from '../../action/select_page.js'
import { connect } from 'react-redux'

var ContentView = React.createClass({
    getInitialState() {

        $.ajax({
            url: '../../../content_text.json',
            dataType: 'json',
            success: function(result) {
                this.setState( {
                    textData: result["content_text"]
                });
            }.bind(this)
        });

        return {
            textData: []
        };
    },

    getPageNumber() {
        if (this.props.params == undefined) {
            return 1;
        }
        else {
            return this.props.params.page;
        }
    },

    render() {
        //console.log('content');
        this.props.dispatch(selectPage(this.getPageNumber()));
        return (
            <div className="container">
                <Content page={this.getPageNumber()}/>
                <SiderBar />
                <Page length={this.state.textData.length} />
            </div>
        )
    }
});

export default connect()(ContentView);
//export default ContentView;